package com.yyh.xiancheng2;

public class Test1 {
    public static void main(String[] args) {
        //使用匿名内部类创建线程任务对象
        Runnable r = new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <= 100; i++) {
                    //线程睡眠，让当前线程睡眠指定的时间
                    System.out.println(Thread.currentThread().getName() + "：" + i);
                }
            }
        };
        Thread t1 = new Thread(r, "线程1");
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i <= 100; i++) {
                    System.out.println(Thread.currentThread().getName()+"：" + i);
                }
            }
        }, "线程2");
        //设置线程优先级
        t1.setPriority(5);
        //设置线程优先级
        t2.setPriority(Thread.MAX_PRIORITY);
        //启动线程
        t1.start();
        t2.start();
    }
}
